
package com.jf.cloud.product.controller.multishop;

import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.product.dto.SpuPriceLogDTO;
import com.jf.cloud.product.model.SpuPriceLog;
import com.jf.cloud.product.service.SpuPriceLogService;
import com.jf.cloud.product.vo.SpuPriceLogVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import ma.glasnost.orika.MapperFacade;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 商品调价记录
 *
 * @author zz
 * @date 2022-06-29 17:48:25
 */
@RestController("multishopSpuPriceLogController")
@RequestMapping("/m/spu_price_log")
@Tag(name = "multishop商品调价记录")
public class SpuPriceLogController {

    @Autowired
    private SpuPriceLogService spuPriceLogService;

    @Autowired
    private MapperFacade mapperFacade;

    @GetMapping("/page")
    @Operation(summary = "获取商品调价记录列表" , description = "分页获取商品调价记录列表")
    public ServerResponseEntity<PageVO<SpuPriceLogVO>> page(@Valid PageDTO pageDTO, @ParameterObject SpuPriceLogDTO spuPriceLogDTO) {
        PageVO<SpuPriceLogVO> spuPriceLogPage = spuPriceLogService.page(pageDTO, spuPriceLogDTO);
        return ServerResponseEntity.success(spuPriceLogPage);
    }

    @GetMapping
    @Operation(summary = "获取商品调价记录" , description = "根据id获取商品调价记录")
    public ServerResponseEntity<SpuPriceLog> getById(@RequestParam Long id) {
        return ServerResponseEntity.success(spuPriceLogService.getById(id));
    }

    @PostMapping
    @Operation(summary = "保存商品调价记录" , description = "保存商品调价记录")
    public ServerResponseEntity<Void> save(@Valid @RequestBody SpuPriceLogDTO spuPriceLogDTO) {
        SpuPriceLog spuPriceLog = mapperFacade.map(spuPriceLogDTO, SpuPriceLog.class);
        spuPriceLog.setId(null);
        spuPriceLogService.save(spuPriceLog);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新商品调价记录" , description = "更新商品调价记录")
    public ServerResponseEntity<Void> update(@Valid @RequestBody SpuPriceLogDTO spuPriceLogDTO) {
        SpuPriceLog spuPriceLog = mapperFacade.map(spuPriceLogDTO, SpuPriceLog.class);
        spuPriceLogService.update(spuPriceLog);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除商品调价记录" , description = "根据商品调价记录id删除商品调价记录")
    public ServerResponseEntity<Void> delete(@RequestParam Long id) {
        spuPriceLogService.deleteById(id);
        return ServerResponseEntity.success();
    }
}
